<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/modules/netw/ProbabilisticBroadcast.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00452.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">ProbabilisticBroadcast.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * ProbabilisticBroadcast.h</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *  Created on: Nov 4, 2008</span>
<a name="l00005"></a>00005 <span class="comment"> *      Author: Damien Piguet</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#ifndef PROBABILISTICBROADCAST_H_</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define PROBABILISTICBROADCAST_H_</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;set&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;MiXiMDefs.h&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &quot;ProbabilisticBroadcastPkt_m.h&quot;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;BaseNetwLayer.h&quot;</span>
<a name="l00017"></a>00017 
<a name="l00027"></a><a class="code" href="a00180.html">00027</a> <span class="keyword">class </span>MIXIM_API <a class="code" href="a00180.html" title="This class offers a data dissemination service using probabilistic broadcast. Each packet which arriv...">ProbabilisticBroadcast</a> : <span class="keyword">public</span> <a class="code" href="a00028.html" title="Base class for the network layer.">BaseNetwLayer</a>
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029 <span class="keyword">private</span>:
<a name="l00032"></a>00032   <a class="code" href="a00180.html" title="This class offers a data dissemination service using probabilistic broadcast. Each packet which arriv...">ProbabilisticBroadcast</a>(<span class="keyword">const</span> <a class="code" href="a00180.html" title="This class offers a data dissemination service using probabilistic broadcast. Each packet which arriv...">ProbabilisticBroadcast</a>&amp;);
<a name="l00035"></a>00035   <a class="code" href="a00180.html" title="This class offers a data dissemination service using probabilistic broadcast. Each packet which arriv...">ProbabilisticBroadcast</a>&amp; <a class="code" href="a00028.html#ac736985952cb46f7340488218e23ae57" title="Assignment operator is not allowed.">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00180.html" title="This class offers a data dissemination service using probabilistic broadcast. Each packet which arriv...">ProbabilisticBroadcast</a>&amp;);
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="keyword">public</span>:
<a name="l00038"></a>00038   <a class="code" href="a00180.html" title="This class offers a data dissemination service using probabilistic broadcast. Each packet which arriv...">ProbabilisticBroadcast</a>()
<a name="l00039"></a>00039     : <a class="code" href="a00028.html" title="Base class for the network layer.">BaseNetwLayer</a>()
<a name="l00040"></a>00040     , broadcastPeriod()
<a name="l00041"></a>00041     , beta(0)
<a name="l00042"></a>00042     , timeToLive()
<a name="l00043"></a>00043     , maxNbBcast(0)
<a name="l00044"></a>00044     , maxFirstBcastBackoff(0)
<a name="l00045"></a>00045     , timeInQueueAfterDeath(0)
<a name="l00046"></a>00046     , <a class="code" href="a00028.html#a9b802bd94a739e6202690d743ecc83a2" title="Length of the NetwPkt header Read from omnetpp.ini.">headerLength</a>(0)
<a name="l00047"></a>00047     , trace(<span class="keyword">false</span>), stats(<span class="keyword">false</span>), <a class="code" href="a00027.html#af32711ea117b066fcd10081a17bb81d4" title="Debug switch for all other modules.">debug</a>(<span class="keyword">false</span>)
<a name="l00048"></a>00048     , broadcastTimer(NULL)
<a name="l00049"></a>00049     , knownMsgIds()
<a name="l00050"></a>00050     , msgQueue()
<a name="l00051"></a>00051     , debugMsgIdSet()
<a name="l00052"></a>00052     , nbDataPacketsReceived(0)
<a name="l00053"></a>00053     , nbDataPacketsSent(0)
<a name="l00054"></a>00054     , nbHops(0)
<a name="l00055"></a>00055     , debugNbMessageKnown(0)
<a name="l00056"></a>00056     , nbDataPacketsForwarded(0)
<a name="l00057"></a>00057     , oneHopLatencies()
<a name="l00058"></a>00058   {}
<a name="l00059"></a>00059 
<a name="l00061"></a>00061     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00028.html#a1e521b5549bfe29ae94d95265c0fe8d2" title="Initialization of the module and some variables.">initialize</a>(<span class="keywordtype">int</span>);
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00025.html#a5ab11502dbeeea89693d29841376a2f7" title="Called when the simulation has finished.">finish</a>();
<a name="l00064"></a>00064 
<a name="l00065"></a>00065 <span class="keyword">protected</span>:
<a name="l00066"></a>00066   <span class="keyword">enum</span> messagesTypes {
<a name="l00067"></a>00067     UNKNOWN=0,
<a name="l00068"></a>00068     BROADCAST_TIMER,
<a name="l00069"></a>00069     NEIGHBOR_TIMER,
<a name="l00070"></a>00070     BETA_TIMER,
<a name="l00071"></a>00071     DATA
<a name="l00072"></a>00072   };
<a name="l00073"></a>00073 
<a name="l00077"></a><a class="code" href="a00214.html">00077</a>   <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="a00214.html" title="Store messages in a structure so that we can keep some information needed by the protocol.">tMsgDesc</a> {
<a name="l00078"></a>00078     ProbabilisticBroadcastPkt* pkt;
<a name="l00079"></a>00079     <span class="keywordtype">int</span>                        nbBcast;     <span class="comment">// number of times the present node has passed the</span>
<a name="l00080"></a>00080                                             <span class="comment">// message through a broadcast attempt.</span>
<a name="l00081"></a>00081     <span class="keywordtype">bool</span>                       initialSend; <span class="comment">// true if message to be sent for first</span>
<a name="l00082"></a>00082                                             <span class="comment">// time by its creator.</span>
<a name="l00083"></a>00083   } <a class="code" href="a00214.html" title="Store messages in a structure so that we can keep some information needed by the protocol.">tMsgDesc</a>;
<a name="l00084"></a>00084 
<a name="l00085"></a>00085   <span class="keyword">typedef</span> std::set&lt;unsigned int&gt; MsgIdSet;
<a name="l00086"></a>00086   <span class="keyword">typedef</span> std::multimap&lt;simtime_t, tMsgDesc*&gt; TimeMsgMap;
<a name="l00087"></a>00087 
<a name="l00089"></a>00089     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00028.html#a0b473fbb2517ac7b0c633afdb002c269" title="Handle messages from upper layer.">handleUpperMsg</a>(cMessage* msg);
<a name="l00090"></a>00090 
<a name="l00092"></a>00092     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00028.html#a58afc64e0a96fe4d80d6b9f53cfd53c6" title="Handle messages from lower layer.">handleLowerMsg</a>(cMessage* msg);
<a name="l00093"></a>00093 
<a name="l00095"></a>00095     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00028.html#a1b6a30a1442d646a41df5acc7ef1e047" title="Handle self messages.">handleSelfMsg</a>(cMessage* msg);
<a name="l00096"></a>00096 
<a name="l00098"></a>00098     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00028.html#a478dcd88ab7a82412deb8075afe61278" title="Handle control messages from lower layer.">handleLowerControl</a>(cMessage* msg);
<a name="l00099"></a>00099 
<a name="l00101"></a>00101     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> messageKnown(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> msgId);
<a name="l00102"></a>00102 
<a name="l00104"></a>00104     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> debugMessageKnown(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> msgId);
<a name="l00105"></a>00105 
<a name="l00112"></a>00112   <span class="keyword">virtual</span> <span class="keywordtype">void</span> insertMessage(simtime_t_cref bcastDelay, <a class="code" href="a00214.html" title="Store messages in a structure so that we can keep some information needed by the protocol.">tMsgDesc</a>* msgDesc);
<a name="l00113"></a>00113 
<a name="l00119"></a>00119   <span class="keyword">virtual</span> <a class="code" href="a00214.html" title="Store messages in a structure so that we can keep some information needed by the protocol.">tMsgDesc</a>* popFirstMessageUpdateQueue(<span class="keywordtype">void</span>);
<a name="l00120"></a>00120 
<a name="l00124"></a>00124   <span class="keyword">virtual</span> <a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a> <a class="code" href="a00028.html#aad9d232f77fa033ffa2f1e7abe8e4af6" title="Encapsulate higher layer packet into an NetwPkt.">encapsMsg</a>(cPacket* msg);
<a name="l00125"></a>00125 
<a name="l00129"></a>00129   <span class="keyword">virtual</span> cPacket*      <a class="code" href="a00028.html#a5e35aa24556a7cab9b6658889e98cb74" title="decapsulate higher layer message from NetwPkt">decapsMsg</a>(<a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a> msg);
<a name="l00130"></a>00130 
<a name="l00141"></a>00141   <span class="keyword">virtual</span> <span class="keywordtype">void</span> insertNewMessage(ProbabilisticBroadcastPkt* pkt, <span class="keywordtype">bool</span> iAmInitialSender = <span class="keyword">false</span>);
<a name="l00142"></a>00142 
<a name="l00147"></a><a class="code" href="a00180.html#a3487bf94d9135c4db3a084a20628719d">00147</a>   simtime_t <a class="code" href="a00180.html#a3487bf94d9135c4db3a084a20628719d" title="Period (in sim time) between two broadcast attempts. Read from omnetpp.ini.">broadcastPeriod</a>;
<a name="l00148"></a>00148 
<a name="l00153"></a><a class="code" href="a00180.html#a94d2b55cb729ca2f8b84a97d1932eca2">00153</a>   <span class="keywordtype">double</span> <a class="code" href="a00180.html#a94d2b55cb729ca2f8b84a97d1932eca2" title="Probability of each broadcast attempt. Read from omnetpp.ini.">beta</a>;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 
<a name="l00156"></a>00156   <span class="comment">/*</span>
<a name="l00157"></a>00157 <span class="comment">   * @brief Default time to live for packets to send.</span>
<a name="l00158"></a>00158 <span class="comment">   */</span>
<a name="l00159"></a>00159   simtime_t timeToLive;
<a name="l00160"></a>00160 
<a name="l00161"></a>00161   <span class="keyword">static</span> <span class="keywordtype">long</span> id_counter;
<a name="l00162"></a>00162 
<a name="l00163"></a>00163   <span class="keyword">static</span> <span class="keywordtype">long</span> getNextID() {
<a name="l00164"></a>00164     <span class="keywordtype">long</span> nextID = id_counter;
<a name="l00165"></a>00165     id_counter++;
<a name="l00166"></a>00166     <span class="keywordflow">return</span> nextID;
<a name="l00167"></a>00167   }
<a name="l00172"></a><a class="code" href="a00180.html#a5bd284f25c3de84f8d82d84d9da2a33a">00172</a>   <span class="keywordtype">int</span> <a class="code" href="a00180.html#a5bd284f25c3de84f8d82d84d9da2a33a" title="Maximal number of broadcast attempts for each packet. Read from omnetpp.ini.">maxNbBcast</a>;
<a name="l00173"></a>00173 
<a name="l00178"></a><a class="code" href="a00180.html#aee51411ce58e319d4b7be77e946f65bc">00178</a>   <span class="keywordtype">int</span> <a class="code" href="a00180.html#aee51411ce58e319d4b7be77e946f65bc" title="Maximal back-off before first broadcast attempt [seconds]. Read from omnetpp.ini.">maxFirstBcastBackoff</a>;
<a name="l00179"></a>00179 
<a name="l00187"></a><a class="code" href="a00180.html#a142757ae77bf5a9500bbe6a956a4b1a0">00187</a>   simtime_t <a class="code" href="a00180.html#a142757ae77bf5a9500bbe6a956a4b1a0" title="How long the message should be kept in queue after its died. That way the message is known if the nod...">timeInQueueAfterDeath</a>;
<a name="l00188"></a>00188 
<a name="l00193"></a><a class="code" href="a00180.html#ac854fd1705c045693986aff67f61b570">00193</a>     <span class="keywordtype">int</span> <a class="code" href="a00180.html#ac854fd1705c045693986aff67f61b570" title="Length of the NetwPkt header Read from omnetpp.ini.">headerLength</a>;
<a name="l00194"></a>00194 
<a name="l00195"></a><a class="code" href="a00180.html#a1712864794da337b2963293f4ca402ec">00195</a>     <span class="keywordtype">bool</span> trace, stats, <a class="code" href="a00180.html#a1712864794da337b2963293f4ca402ec" title="Debug switch for all other modules.">debug</a>;
<a name="l00196"></a>00196 
<a name="l00197"></a>00197     <span class="comment">// perform broadcast attempt for the first message in the list each time it expires</span>
<a name="l00198"></a>00198     cMessage* broadcastTimer;
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     <span class="comment">// we use two containers: a set which stores the ID&#39;s of the messages which are kept</span>
<a name="l00201"></a>00201     <span class="comment">// in memory and a multimap which stores a pair &lt;Key, Value&gt; where Key is the next</span>
<a name="l00202"></a>00202     <span class="comment">// broadcasting attempt time of the message and Value is a pointer to the message</span>
<a name="l00203"></a>00203     <span class="comment">// (see typedef&#39;s above).</span>
<a name="l00204"></a>00204     MsgIdSet knownMsgIds;
<a name="l00205"></a>00205     TimeMsgMap msgQueue;
<a name="l00206"></a>00206     MsgIdSet debugMsgIdSet;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208     <span class="comment">// variables for statistics</span>
<a name="l00209"></a>00209     <span class="keywordtype">long</span> nbDataPacketsReceived; <span class="comment">// total number of received packets from lower layer</span>
<a name="l00210"></a>00210     <span class="keywordtype">long</span> nbDataPacketsSent;
<a name="l00211"></a>00211     <span class="keywordtype">long</span> nbHops;
<a name="l00212"></a>00212     <span class="keywordtype">int</span> debugNbMessageKnown;
<a name="l00213"></a>00213     <span class="keywordtype">long</span> nbDataPacketsForwarded;
<a name="l00214"></a>00214     <span class="comment">// records the time packets take between submission to MAC layer and reception at</span>
<a name="l00215"></a>00215     <span class="comment">// networking layer (over one hop).</span>
<a name="l00216"></a>00216     cOutVector oneHopLatencies;
<a name="l00217"></a>00217 };
<a name="l00218"></a>00218 
<a name="l00219"></a>00219 <span class="preprocessor">#endif </span><span class="comment">/* PROBABILISTICBROADCAST_H_ */</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>ProbabilisticBroadcast.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
